@inherits AppComponentBase

<section>
    <BitStack HorizontalAlign="BitAlignment.Center">
        @if (Loading)
        {
            <BitShimmer Shape="BitShimmerShape.Circle" Height="4.5rem" />
            <BitShimmer Shape="BitShimmerShape.Rectangle" Height="1.5rem" Width="12.5rem" />
            <br />
            <BitShimmer Shape="BitShimmerShape.Rectangle" Height="1.5rem" Width="25rem" />
            <BitShimmer Shape="BitShimmerShape.Rectangle" Height="1.5rem" Width="25rem" />
            <BitShimmer Shape="BitShimmerShape.Rectangle" Height="1.5rem" Width="25rem" />
            <BitShimmer Shape="BitShimmerShape.Rectangle" Height="1.5rem" Width="25rem" />
        }
        else
        {
            <BitFileUpload @ref="fileUploadRef"
                           AutoReset
                           AutoUpload
                           HideFileView
                           Accept="image/*"
                           MaxSize="1024 * 1024 * 10"
                           UploadUrlProvider="GetUploadUrl"
                           OnUploading="() => isUploading = true"
                           OnUploadFailed="HandleOnUploadFailed"
                           OnUploadComplete="WrapHandled(HandleOnUploadComplete)"
                           UploadRequestHttpHeadersProvider="WrapHandled(GetUploadRequestHeaders)">
                <LabelTemplate>
                    <BitStack HorizontalAlign="BitAlignment.Center">
                        @if (isUploading is false)
                        {
                            <BitPersona HidePersonaDetails
                                        ImageUrl="@ProfileImageUrl"
                                        PrimaryText="@CurrentUser?.FullName"
                                        Size=@BitPersonaSize.Size72
                                        Presence="@(IsOnline is null ? BitPersonaPresence.None : IsOnline is true ? BitPersonaPresence.Online : BitPersonaPresence.Offline)" />
                            <BitLink OnClick="() => fileUploadRef.Browse()" NoUnderline>
                                <BitText>@Localizer[nameof(AppStrings.UploadNewImage)]</BitText>
                            </BitLink>
                        }
                        else
                        {
                            <BitShimmer Shape="BitShimmerShape.Circle" Height="4.5rem" />
                            <BitShimmer Shape="BitShimmerShape.Rectangle" Height="1.5rem" Width="12.5rem" />
                        }
                    </BitStack>
                </LabelTemplate>
            </BitFileUpload>

            @if (CurrentUser?.HasProfilePicture is true)
            {
                <BitButton IsLoading=@isSaving OnClick="WrapHandled(RemoveProfileImage)" Color="BitColor.Error">
                    @Localizer[nameof(AppStrings.Remove)]
                </BitButton>
            }
            <br />
            <EditForm Model="editUserDto" OnValidSubmit="WrapHandled(SaveProfile)" novalidate class="max-width">
                <AppDataAnnotationsValidator />

                <BitStack FillContent>
                    <BitTextField @bind-Value="editUserDto.FullName"
                                  Label="@Localizer[nameof(AppStrings.FullName)]"
                                  Placeholder="@Localizer[nameof(AppStrings.FullName)]" />
                    <ValidationMessage For="@(() => editUserDto.FullName)" />

                    <BitDatePicker Responsive @bind-Value="editUserDto.BirthDate"
                                   Class="edit-profile-dtp"
                                   Label="@Localizer[nameof(AppStrings.BirthDate)]"
                                   GoToTodayTitle="@Localizer[nameof(AppStrings.GoToToday)]"
                                   Placeholder="@Localizer[nameof(AppStrings.SelectBirthDate)]" />
                    <ValidationMessage For="@(() => editUserDto.BirthDate)" />

                    <BitChoiceGroup Horizontal
                                    @bind-Value="editUserDto.Gender"
                                    TItem="BitChoiceGroupOption<Gender>" TValue="Gender"
                                    Label="@Localizer[nameof(AppStrings.Gender)]">
                        <BitChoiceGroupOption Value="@Gender.Male" Text="@Localizer[nameof(AppStrings.GenderMale)]" />
                        <BitChoiceGroupOption Value="@Gender.Female" Text="@Localizer[nameof(AppStrings.GenderFemale)]" />
                        <BitChoiceGroupOption Value="@Gender.Other" Text="@Localizer[nameof(AppStrings.GenderOther)]" />
                    </BitChoiceGroup>

                    <BitButton IsLoading="isSaving"
                               ButtonType="BitButtonType.Submit"
                               Title="@Localizer[nameof(AppStrings.Save)]">
                        @Localizer[nameof(AppStrings.Save)]
                    </BitButton>
                </BitStack>
            </EditForm>
        }
        <br />
    </BitStack>
</section>
